<template>
  <a-layout style="min-height: 100vh">
    <a-layout-sider v-model:collapsed="collapsed" collapsible>
      <div class="logo" />
      <a-menu 
      v-model:selectedKeys="selectedKeys" 
      :open-keys="openKeys" 
      theme="dark" mode="inline"
      @openChange="onOpenChange"
      >
        <a-sub-menu key="sub1">
          <template #title>
            <span>
              <user-outlined />
              <span>系统管理</span>
            </span>
          </template>
          <a-menu-item key="3"><router-link to="/test">权限管理</router-link></a-menu-item>
          <a-menu-item key="4">管理员管理</a-menu-item>
          <a-menu-item key="5">职位管理</a-menu-item>
          <a-menu-item key="6">资源管理</a-menu-item>
        </a-sub-menu>
        <a-sub-menu key="sub2">
          <template #title>
            <span>
              <File-outlined />
              <span>任务管理</span>
            </span>
          </template>
          <a-menu-item key="1">
            <router-link to="/plan_list">任务列表</router-link>
          </a-menu-item>
          <a-menu-item key="10">
            <router-link to="/test">测试</router-link>
          </a-menu-item>
        </a-sub-menu>

        <a-sub-menu key="sub3">
          <template #title>
            <span>
              <Pie-chartOutlined/>
              <span>统计管理</span>
            </span>
          </template>
          <a-menu-item key="1">
            <router-link to="/plan_list">统计列表</router-link>
          </a-menu-item>
        </a-sub-menu>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0" >头部</a-layout-header>
      <a-layout-content style="margin: 0 16px">
        <router-view />
      </a-layout-content>
      <a-layout-footer style="text-align: center">
        Ant Design ©2018 Created by Ant UED
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>
<script>
import { UserOutlined, FileOutlined, PieChartOutlined} from '@ant-design/icons-vue';
import { ref, reactive, toRefs } from 'vue';
export default {
  components: {
    UserOutlined,
    FileOutlined,
    PieChartOutlined
  },
  setup(){
    let collapsed = ref(false)
    const state = reactive({
      rootSubmenuKeys: ['sub1', 'sub2', 'sub4'],
      openKeys: ['sub2'],
      selectedKeys: [],
    });

    const onOpenChange = openKeys => {
      const latestOpenKey = openKeys.find(key => state.openKeys.indexOf(key) === -1);

      if (state.rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
        state.openKeys = openKeys;
      } else {
        state.openKeys = latestOpenKey ? [latestOpenKey] : [];
      }
    };
    return {
      collapsed,
      ...toRefs(state),
      onOpenChange

    }
  },
};
</script>
<style>
#components-layout-demo-side .logo {
  height: 32px;
  margin: 16px;
  background: rgba(255, 255, 255, 0.3);
}

.site-layout .site-layout-background {
  background: #fff;
}
[data-theme='dark'] .site-layout .site-layout-background {
  background: #141414;
}
</style>